import {
    createDictionary,
    createDictionaryItem,
    deleteDictionary,
    deleteDictionaryItem,
    getAllDictionaryService,
    getDicionaries,
    getDictionary,
    getDictionaryByKeyService,
    getDictionaryItems,
    updateDictionary,
    updateDictionaryItem,
} from "@/services/common/dictionary";
import express from "express";

const router = express.Router();
router.get("/items", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.path = '/admin-api/dictionary/items'
        #swagger.description = '获取分页数据'
        #swagger.method = 'GET'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.parameters['page'] = { in: 'query', description: '分页页号', type: 'integer' }
        #swagger.parameters['pageSize'] = { in: 'query', description: '分页每页个数', type: 'integer' }
        #swagger.parameters['_id'] = { in: 'query', description: '字典ID', type: 'string' }
        #swagger.parameters['key'] = { in: 'query', description: '字典键', type: 'string' }
        #swagger.parameters['label'] = { in: 'query', description: '字典数据项名称', type: 'string' }
        #swagger.parameters['value'] = { in: 'query', description: '字典数据项值', type: 'string' }
    */
    getDictionaryItems(req, res);
});

router.post("/items", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.path = '/admin-api/dictionary/items'
        #swagger.description = '创建字典数据'
        #swagger.method = 'POST'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        properties: {
                            dictionaryId: { type: "string", description: "字典ID" },
                            label: { type: "string", description: "字典项的标签" },
                            value: { type: "string", description: "字典项的值" },
                            backgroundColor: { type: "string", description: "字典项的背景颜色" },
                            status: { type: "boolean", description: "启用状态，true 表示启用" },
                            sort: { type: "number", description: "排序字段" },
                            remark: { type: "string", description: "备注信息" }
                        },
                        required: ["dictionaryId", "label", "value"]
                    }
                }
            }
        }
    */
    createDictionaryItem(req, res);
});

router.put("/items", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.path = '/admin-api/dictionary/items'
        #swagger.description = '更新字典数据'
        #swagger.method = 'PUT'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        properties: {
                            dictionaryId: { type: "string", description: "字典ID" },
                            label: { type: "string", description: "字典项的标签" },
                            value: { type: "string", description: "字典项的值" },
                            backgroundColor: { type: "string", description: "字典项的背景颜色" },
                            status: { type: "boolean", description: "启用状态，true 表示启用" },
                            sort: { type: "number", description: "排序字段" },
                            remark: { type: "string", description: "备注信息" }
                        }
                    }
                }
            }
        }
    */
    updateDictionaryItem(req, res);
});

router.delete("/items", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.path = '/admin-api/dictionary/items'
        #swagger.description = '删除字典数据'
        #swagger.method = 'DELETE'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        properties: {
                            _id: { type: "string", description: "字典数据ID", required: true },
                        }
                    }
                }
            }
        }
    */
    deleteDictionaryItem(req, res);
});

router.get("/getDictionaryByKey", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.path = '/admin-api/dictionary/getDictionaryByKey'
        #swagger.description = '获取字典详情'
        #swagger.method = 'GET'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.parameters['key'] = { in: 'query', description: '字典键', type: 'string' }
    */
    getDictionaryByKeyService(req, res);
});

router.get("/all", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.path = '/admin-api/dictionary/all'
        #swagger.description = '获取所有字典'
        #swagger.method = 'GET'
        #swagger.security = [{"bearerAuth": []}]
    */
    getAllDictionaryService(req, res);
});

router.get("/", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.path = '/admin-api/dictionary'
        #swagger.description = '获取字典分页'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.parameters['page'] = { in: 'query', description: '分页页号', type: 'integer' }
        #swagger.parameters['pageSize'] = { in: 'query', description: '分页每页个数', type: 'integer' }
        #swagger.parameters['_id'] = { in: 'query', description: '字典ID', type: 'string' }
        #swagger.parameters['key'] = { in: 'query', description: '字典键', type: 'string' }
        #swagger.parameters['title'] = { in: 'query', description: '字典名称', type: 'string' }
    */
    getDicionaries(req, res);
});

router.get("/:_id", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.path = '/admin-api/dictionary/{_id}'
        #swagger.description = '获取指定字典'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.parameters['_id'] = { in: 'path', description: '字典ID', type: 'string', required: true }
    */
    getDictionary(req, res);
});

router.post("/", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.path = '/admin-api/dictionary'
        #swagger.description = '创建字典'
        #swagger.method = 'POST'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        properties: {
                            title: { type: 'string', description: '字典名称' },
                            key: { type: 'string', description: '字典键' },
                            status: { type: 'boolean', description: '状态' },
                            remark: { type: 'string', description: '备注' },
                            dictionaryItems: {
                                type: 'array',
                                items: {
                                    type: 'object',
                                    properties: {
                                        label: { type: "string", description: "字典项的标签" },
                                        value: { type: "string", description: "字典项的值" },
                                        backgroundColor: { type: "string", description: "字典项的背景颜色" },
                                        status: { type: "boolean", description: "启用状态，true 表示启用" },
                                        sort: { type: "number", description: "排序字段" },
                                        remark: { type: "string", description: "备注信息" }
                                    },
                                    required: ['label', 'value']
                                }
                            }
                        },
                        required: ['title','key','dictionaryItems']
                    }
                }
            }
        }
    */
    createDictionary(req, res);
});

router.put("/", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.path = '/admin-api/dictionary'
        #swagger.description = '创建字典'
        #swagger.method = 'PUT'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        properties: {
                            _id: { type: 'string', description: '字典ID' },
                            title: { type: 'string', description: '字典名称' },
                            key: { type: 'string', description: '字典键' },
                            status: { type: 'boolean', description: '状态' },
                            remark: { type: 'string', description: '备注' },
                            dictionaryItems: {
                                type: 'array',
                                items: {
                                    type: 'object',
                                    properties: {
                                        label: { type: "string", description: "字典项的标签" },
                                        value: { type: "string", description: "字典项的值" },
                                        backgroundColor: { type: "string", description: "字典项的背景颜色" },
                                        status: { type: "boolean", description: "启用状态，true 表示启用" },
                                        sort: { type: "number", description: "排序字段" },
                                        remark: { type: "string", description: "备注信息" }
                                    },
                                    required: ['label', 'value']
                                }
                            }
                        },
                        required: ['_id']
                    }
                }
            }
        }
    */
    updateDictionary(req, res);
});

router.delete("/", (req, res) => {
    /*
        #swagger.tags = ['管理端字典']
        #swagger.description = '删除字典'
        #swagger.path = '/admin-api/dictionary'
        #swagger.security = [{"bearerAuth": []}]
        #swagger.requestBody = {
            required: true,
            content: {
                "application/json": {
                    schema: {
                        type: "object",
                        properties: {
                            _id: { type: "string", description: "字典数据ID", required: true },
                        }
                    }
                }
            }
        }
    */
    deleteDictionary(req, res);
});

export default router;
